<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="企业" prop="enterpriseId">
           <el-select   clearable
          v-model="queryParams.enterpriseId" filterable
          placeholder="请选择企业"
          size="small"
        >
          <el-option
            v-for="item in qyEnterpriseList"
            :key="item.id"
            :label="item.enterpriseName"
            :value="item.id"
          >
          </el-option>
        </el-select>
        </el-form-item>
      <el-form-item label="统计月份" prop="statisticsMonth">
        <el-date-picker
          clearable
          size="small"
          v-model="queryParams.statisticsMonth"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择统计月份"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="项目来源地" prop="projectSource">
        <el-input
          v-model="queryParams.projectSource"
          placeholder="请输入项目来源地"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['energy:qyStatisticsReport:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['energy:qyStatisticsReport:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['energy:qyStatisticsReport:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['energy:qyStatisticsReport:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="qyStatisticsReportList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="企业" align="center" prop="enterpriseName" />
      <el-table-column
        label="统计月份"
        align="center"
        prop="statisticsMonth"
        width="120"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.statisticsMonth, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目来源地" align="center" prop="projectSource" />
      <el-table-column
        label="公司总投资(万元)"
        align="center"
        prop="totalInvestment"
      />
      <el-table-column
        label="本月工业总产值(万元)"
        align="center"
        prop="currentMonthOutput"
      />
      <el-table-column
        label="1-上月工业总产值(万元)"
        align="center"
        prop="last1MonthOutput"
      />
      <el-table-column
        label="1-本月工业总产值(万元)"
        align="center"
        prop="current1MonthOutput"
      />
      <el-table-column
        label="工业总产值同期(万元)"
        align="center"
        prop="totalOutputPeriod"
      />
      <el-table-column
        label="工业总产值同比"
        align="center"
        prop="totalOutputRatio"
      />
      <el-table-column
        label="本月主营业务收入(万元)"
        align="center"
        prop="currentProfit"
      />
      <el-table-column
        label="1-本月主营业务收入(万元)"
        align="center"
        prop="current1Profit"
      />
      <el-table-column
        label="1-上月主营业务收入(万元)"
        align="center"
        prop="last1Profit"
      />
      <el-table-column
        label="主营业务收入同期"
        align="center"
        prop="profitPeriod"
      />
      <el-table-column
        label="主营业务收入同比"
        align="center"
        prop="profitRatio"
      />
      <el-table-column label="占地面积" align="center" prop="areaCovered" />
      <el-table-column label="管理者人数" align="center" prop="managerNum" />
      <el-table-column label="用工人数" align="center" prop="worker" />
      <el-table-column label="净用地面积" align="center" prop="actualArea" />
      <el-table-column label="填表人" align="center" prop="preparer" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column
        label="上报时间"
        align="center"
        prop="reportTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center" width="150"  fixed="right"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['energy:qyStatisticsReport:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['energy:qyStatisticsReport:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改统计报送对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" size="small" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="企业" prop="enterpriseId">
          <el-select            clearable
            v-model="form.enterpriseId" filterable
            placeholder="请选择企业"
          >
            <el-option
              v-for="item in qyEnterpriseList"
              :key="item.id"
              :label="item.enterpriseName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="统计月份" prop="statisticsMonth">
          <el-date-picker
            clearable
            size="small"
            v-model="form.statisticsMonth"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择统计月份"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目来源地" prop="projectSource">
          <el-input
            v-model="form.projectSource"
            placeholder="请输入项目来源地"
          />
        </el-form-item>
        <el-form-item label="公司总投资(万元)" prop="totalInvestment">
          <el-input
            v-model="form.totalInvestment"
            placeholder="请输入公司总投资(万元)"
          />
        </el-form-item>
        <el-form-item label="本月工业总产值(万元)" prop="currentMonthOutput">
          <el-input
            v-model="form.currentMonthOutput"
            placeholder="请输入本月工业总产值(万元)"
          />
        </el-form-item>
        <el-form-item label="1-上月工业总产值(万元)" prop="last1MonthOutput">
          <el-input
            v-model="form.last1MonthOutput"
            placeholder="请输入1-上月工业总产值(万元)"
          />
        </el-form-item>
        <el-form-item label="1-本月工业总产值(万元)" prop="current1MonthOutput">
          <el-input
            v-model="form.current1MonthOutput"
            placeholder="请输入1-本月工业总产值(万元)"
          />
        </el-form-item>
        <el-form-item label="工业总产值同期(万元)" prop="totalOutputPeriod">
          <el-input
            v-model="form.totalOutputPeriod"
            placeholder="请输入工业总产值同期(万元)"
          />
        </el-form-item>
        <el-form-item label="工业总产值同比" prop="totalOutputRatio">
          <el-input
            v-model="form.totalOutputRatio"
            placeholder="请输入工业总产值同比"
          />
        </el-form-item>
        <el-form-item label="本月主营业务收入(万元)" prop="currentProfit">
          <el-input
            v-model="form.currentProfit"
            placeholder="请输入本月主营业务收入(万元)"
          />
        </el-form-item>
        <el-form-item label="1-本月主营业务收入(万元)" prop="current1Profit">
          <el-input
            v-model="form.current1Profit"
            placeholder="请输入1-本月主营业务收入(万元)"
          />
        </el-form-item>
        <el-form-item label="1-上月主营业务收入(万元)" prop="last1Profit">
          <el-input
            v-model="form.last1Profit"
            placeholder="请输入1-上月主营业务收入(万元)"
          />
        </el-form-item>
        <el-form-item label="主营业务收入同期" prop="profitPeriod">
          <el-input
            v-model="form.profitPeriod"
            placeholder="请输入主营业务收入同期"
          />
        </el-form-item>
        <el-form-item label="主营业务收入同比" prop="profitRatio">
          <el-input
            v-model="form.profitRatio"
            placeholder="请输入主营业务收入同比"
          />
        </el-form-item>
        <el-form-item label="占地面积" prop="areaCovered">
          <el-input v-model="form.areaCovered" placeholder="请输入占地面积" />
        </el-form-item>
        <el-form-item label="管理者人数" prop="managerNum">
          <el-input v-model="form.managerNum" placeholder="请输入管理者人数" />
        </el-form-item>
        <el-form-item label="用工人数" prop="worker">
          <el-input v-model="form.worker" placeholder="请输入用工人数" />
        </el-form-item>
        <el-form-item label="净用地面积" prop="actualArea">
          <el-input v-model="form.actualArea" placeholder="请输入净用地面积" />
        </el-form-item>
        <el-form-item label="填表人" prop="preparer">
          <el-input v-model="form.preparer" placeholder="请输入填表人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="上报时间" prop="reportTime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.reportTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择上报时间"
          >
          </el-date-picker>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listQyStatisticsReport,
  getQyStatisticsReport,
  delQyStatisticsReport,
  addQyStatisticsReport,
  updateQyStatisticsReport,
} from "@/api/smartParks/energy/qyStatisticsReport";
import { listQyEnterprise } from "@/api/smartParks/merchants/merchantsCompanySettlein";
export default {
  name: "QyStatisticsReport",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 统计报送表格数据
      qyStatisticsReportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseId: null,
        statisticsMonth: null,
        projectSource: null,
        tenantId: null,
      },
      // 表单参数
      form: {},
      qyEnterpriseList: [],
      // 表单校验
      rules: {
        enterpriseId: [
          { required: true, message: "企业Id不能为空", trigger: "blur" },
        ],
        statisticsMonth: [
          { required: true, message: "统计月份不能为空", trigger: "blur" },
        ],
        projectSource: [
          { required: true, message: "项目来源地不能为空", trigger: "blur" },
        ],
        delFlag: [
          {
            required: true,
            message: "删除标志(0正常 1删除)不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
    listQyEnterprise().then((response) => {
      this.qyEnterpriseList = response.rows;
    });
  },
  methods: {
    /** 查询统计报送列表 */
    getList() {
      this.loading = true;
      listQyStatisticsReport(this.queryParams).then((response) => {
        this.qyStatisticsReportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        enterpriseId: null,
        statisticsMonth: null,
        projectSource: null,
        totalInvestment: null,
        currentMonthOutput: null,
        last1MonthOutput: null,
        current1MonthOutput: null,
        totalOutputPeriod: null,
        totalOutputRatio: null,
        currentProfit: null,
        current1Profit: null,
        last1Profit: null,
        profitPeriod: null,
        profitRatio: null,
        areaCovered: null,
        managerNum: null,
        worker: null,
        actualArea: null,
        preparer: null,
        phone: null,
        reportTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null,
        tenantId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加统计报送";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getQyStatisticsReport(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改统计报送";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateQyStatisticsReport(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQyStatisticsReport(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除统计报送编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delQyStatisticsReport(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "energy/qyStatisticsReport/export",
        {
          ...this.queryParams,
        },
        `energy_qyStatisticsReport.xlsx`
      );
    },
  },
};
</script>
